<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">

		<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
		<link rel="stylesheet" href="css/login.css" />
		<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
		<script src="bootstrap/js/bootstrap.min.js"></script>

		
	</head>

	<body>
		<div id="_start" style="left: 350px; height: 520px; width: 400px;border: 1px solid rgba(0,0,0,.25);">
			<div id="_close" style="height: 40px; width: 40px;">
				<span class="glyphicon glyphicon-remove"></span>
			</div>
			<br> 
			<!-- 会员注册 -->
			<div id="regist_container" style="display: block;">
				<div id="lab1">
					<span id="lab_login">会员注册</span>
				</div>
				<div id="form_container2" style="padding-top: 25px;">
					
					<input type="text" class="form-control"  placeholder="邮箱" id="regist_account">
					<input type="password" class="form-control" placeholder="密码" id="regist_password1">
					<input type="password" class="form-control" placeholder="确认密码" id="regist_password2">
					<input type="text" class="form-control" placeholder="验证码" id="regist_vcode">
					<!--<button id="getVCode" type="button" class="btn btn-success" >获取验证码</button>-->
					<input id="getVCode" type="button" class="btn btn-success" value="点击发送验证码" onclick="sendCode(this)">

				</div>
				<input type="button" value="注册" onclick="register(this)" class="btn btn-success" id="regist_btn">
			</div>
		</div>
	</body>
	<script type="text/javascript">
		var clock = '';
		var nums = 10;
		var btn;
		function sendCode(thisBtn) {
		console.log('发送验证码');
			var email=$('#regist_account').val();
		  $.ajax({
            type: 'GET',
            url: "/api/code/create/"+email,
            data: {
               
            },
            success: function (msg) {
console.log('msg',msg);
                if (msg.status == 200) {
                   //js使用sessionStorage保存token【单页存储日后需改为浏览器存储】
                    window.location.href="login.html"; 
                } else {
                   
                }
            },
            dataType: "json"
        });
		
		btn = thisBtn;
			btn.disabled = true; //将按钮置为不可点击
			btn.value = '重新获取（'+nums+'）';
			clock = setInterval(doLoop, 1000); //一秒执行一次
		}

		
		
		
		function register(thisBtn) {
		console.log('注册');
		var email=$('#regist_account').val();
		var regist_password1=$('#regist_password1').val();
		var regist_password2=$('#regist_password2').val();
		var regist_vcode=$('#regist_vcode').val();
		  $.ajax({
            type: 'GET',
            url: "/api/user/register/"+email+"/"+regist_password1+"/"+regist_vcode,
            data: {
               
            },
            success: function (msg) {
                 console.log('msg',msg);
                if (msg.status == 200) {
                   
                   window.location.href="login.html"; 
                } else {
                   
                }
            },
            dataType: "json"
        });
			
		}
		
		
		
		function doLoop() {
			nums--;
			if (nums > 0) {
				btn.value = '重新获取（'+nums+'）';
			} else {
				clearInterval(clock); //清除js定时器
				btn.disabled = false;
				btn.value = '点击发送验证码';
				nums = 10; //重置时间
			}
		}
		
		$(document).ready(function(){
			
		});
	</script>

</html>